package com.tueye.web.exception;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
/**
 * Try to resolve the given exception that got thrown during on handler execution, returning a ModelAndView that represents a specific error page if appropriate.<br/> 
 * Parameters:
 *	request - current HTTP request
 *	response - current HTTP response
 *	handler - the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
 *	ex - the exception that got thrown during handler execution 
 *	Returns: a corresponding ModelAndView to forward to, or null for default processing
 *  422012058
 * @author hanxiaowei
 *
 */

public class TuEyeHandlerExceptionResolver implements HandlerExceptionResolver {
	
	private final  Log log = LogFactory.getLog(getClass()); 

	@SuppressWarnings("unchecked")
	@Override
	public ModelAndView resolveException(HttpServletRequest request, 
            HttpServletResponse response, Object handler, Exception ex) {
		
		log.warn(" TuEye -- "+handler.getClass().getName()+"-- exception: " + ex.getMessage() ); 
		ex.printStackTrace();
		ModelAndView mav = new ModelAndView("/pages/index");
        Map exinfo = new HashMap(); 
        exinfo.put("ex", ex.getClass().getSimpleName()); 
        exinfo.put("error", ex.getMessage()); 
        mav.addAllObjects(exinfo);
        return mav; 

	}

}
